package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/nursing_project")//总的路径
@Api(tags = "护理项目管理")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping()
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            //url参数
            @RequestParam(value = "name", required = false)     // required表示是否必须，如果不写，默认为true
            String name,
                                                          //但是新的springboot版本，比如2.0以上的版本可能是默认false
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false)  //默认为true时必须要填
            Integer status,

            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1")
            Integer pageNum,

            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10")
            Integer pageSize) {

        PageResponse<NursingProjectVo> nursingPage = nursingProjectService.sellectByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingPage);
    }

    @PostMapping()
    @ApiOperation(value = "添加护理项目", notes = "用于添加新的护理项目")
    public ResponseResult add(@RequestBody @ApiParam(value = "护理项目数据传输对象", required = true) NursingProjectDto dto) {
        nursingProjectService.insert(dto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目", notes = "根据id查询护理项目")
    public ResponseResult<NursingProjectVo> sellectById(@PathVariable @ApiParam(value = "护理项目ID", required = true) Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.sellectById(id);
        return ResponseResult.success(nursingProjectVo);

    }

    @PutMapping
    @ApiOperation(value="修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.update(nursingProjectDTO);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理项目状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.updateStatus(id, status);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete(@PathVariable Long id){
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }
}
